<!doctype html>
<html lang="zh-CN" th:replace="admin-layout :: layout(~{::title}, ~{}, ~{::script}, ~{::body}, 'user-list')"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <title th:text="${id}?'修改用户':_">添加用户</title>
    <script th:inline="javascript">
        $("#submitBtn").click(function(){
            var loginName=$("input[name='loginName']").val();
            if(!loginName){
                msgAlert("请输入账号")
                return;
            }
            var name=$("input[name='name']").val();
            if(!name){
                msgAlert("请输入姓名")
                return;
            }
            if ($("#id").val()==undefined) {
                var password = $("input[name='password']").val();
                if (!password) {
                    msgAlert("请输入密码")
                    return;
                }
            }
            ajaxJson("/admin/user/ajax/save",$("#form").serialize(),function(res){
                if(res.status){
                    location.href="/admin/user/list";
                }else{
                    msgTips(res.message);
                }
            })
        })
    </script>
</head>
<body>
<!--<ol class="breadcrumb">
    <li><a th:href="@{/admin/user/list}">用户列表</a></li>
    <li class="active"th:text="${data}?'修改用户':_">添加用户</li>
</ol>-->
<form class="form-horizontal" id="form">
    <input type="hidden" name="id" th:if="${data}" th:value="${data.id}" id="id">
    <div class="form-group">
        <label class="col-sm-2 col-md-2 col-lg-3 control-label"><span class="text-danger">*&nbsp;</span>用户账号</label>
        <div class="col-sm-8 col-md-8 col-lg-6">
            <input type="text" class="form-control" placeholder="账号" name="loginName" th:value="${data}?${data.loginName}">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 col-md-2 col-lg-3 control-label"><span class="text-danger">*&nbsp;</span>用户姓名</label>
        <div class="col-sm-8 col-md-8 col-lg-6">
            <input type="text" class="form-control" placeholder="姓名" name="name" th:value="${data}?${data.name}">
        </div>
    </div>
    <div class="form-group" th:unless="${data}">
        <label class="col-sm-2 col-md-2 col-lg-3 control-label"><span class="text-danger">*&nbsp;</span>用户密码</label>
        <div class="col-sm-8 col-md-8 col-lg-6">
            <input type="text" class="form-control" placeholder="密码" name="password" value="123456">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 col-md-2 col-lg-3 control-label"><span class="text-danger">*&nbsp;</span>用户性别</label>
        <div class="col-sm-8 col-md-8 col-lg-6">
            <select class="form-control" name="gender">
                <option value="A" th:selected="${data}?${data.gender}=='A'">其他</option>
                <option value="B" th:selected="${data}?${data.gender}=='B'">男</option>
                <option value="C" th:selected="${data}?${data.gender}=='C'">女</option>
            </select>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 col-md-2 col-lg-3 control-label"><span class="text-danger">*&nbsp;</span>用户类型</label>
        <div class="col-sm-8 col-md-8 col-lg-6">
            <select class="form-control" name="type">
                <option value="B" th:selected="${data}?${data.type}=='B'">普通用户</option>
                <option value="A" th:selected="${data}?${data.type}=='A'">管理员</option>
            </select>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-offset-2 col-md-offset-2 col-lg-offset-3 col-sm-8 col-md-8 col-lg-6">
            <button type="button" class="btn btn-primary" id="submitBtn">提交</button>
            <button type="button" class="btn btn-warning backBtn">返回</button>
        </div>
    </div>
</form>
</body>
</html>